/*
 *接口编写处...
*如果接口需要做Action的权限验证，请在Action上使用属性
*如: [ApiActionPermission("zm_data_record",Enums.ActionPermissionOptions.Search)]
 */
using KS3;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.DependencyInjection;
using VOL.AppManager.IServices;
using VOL.Core.Dapper;
using VOL.Core.Enums;
using VOL.Core.Filters;
using VOL.Core.ManageUser;
using VOL.Core.Middleware;
using VOL.Core.Services;
using VOL.Core.Utilities;
using VOL.Entity.新文件夹;

namespace VOL.AppManager.Controllers
{
    public partial class zm_data_recordController
    {
        private readonly Izm_data_recordService _service;//访问业务代码
        private readonly IHttpContextAccessor _httpContextAccessor;
        private readonly KS3Client _kS3Client;
        SqlDapper dapper = new SqlDapper();
        private WebResponseContent _baseWebResponseContent { get; set; }


        [ActivatorUtilitiesConstructor]
        public zm_data_recordController(
            Izm_data_recordService service,
            KS3Client client,
            IHttpContextAccessor httpContextAccessor
        )
        : base(service
              , client
              )
        {
            _kS3Client = client;
            _service = service;
            _httpContextAccessor = httpContextAccessor;
        }


        [HttpPost, Route("GetDetaileByID")]
        public ActionResult GetDetaileByID([FromQuery] string id)
        {
            var res = InvokeService("GetDetaileByID", new object[] { id }) as WebResponseContent; ;
            Logger.Info(Core.Enums.LoggerType.Info, id, res.Status ? "Ok" : res.Message);
            return JsonNormal(res);
        }

        [HttpPost, Route("GetProjectCount")]
        [ApiActionPermission("zm_data_record", ActionPermissionOptions.Search)]
        public ActionResult GetProjectCount([FromBody] zmdatarecordQuery param)
        {

            if (!string.IsNullOrEmpty(UserContext.Current.XzqName))
            {
                param.projectname = UserContext.Current.ProvMc + "-" + UserContext.Current.CityMc + "-" + UserContext.Current.XzqName;
                param.key = UserContext.Current.XzqDm;
                param.xzqdm = UserContext.Current.XzqDm;
            }
            else
            {
                param.projectname = UserContext.Current.ProvMc + "-" + UserContext.Current.CityMc;
                param.key = UserContext.Current.CityDm;
                param.citydm = UserContext.Current.CityDm;
            }
            var res = InvokeService("GetProjectCount", new object[] { param }) as WebResponseContent; ;
            Logger.Info(Core.Enums.LoggerType.Info, "获取项目提交次数", res.Status ? "Ok" : res.Message);
            return JsonNormal(res);
        }

        [ActionLog("查询")]
        [ApiActionPermission("zm_data_record", ActionPermissionOptions.Search)]
        [HttpPost, Route("GetData")]
        public ActionResult GetData([FromBody] zmdatarecordQuery param)
        {
            if (UserContext.Current.RoleId == 132 || UserContext.Current.RoleId == 133 || UserContext.Current.RoleId == 126 || UserContext.Current.RoleId == 137)
            {
                param.xzqdm = UserContext.Current.XzqDm;
                param.citydm = UserContext.Current.CityDm;
                param.provcode = UserContext.Current.ProvCode;

            }

            if (UserContext.Current.RoleId == 126 || UserContext.Current.RoleId == 137)
            {
                param.userid = UserContext.Current.UserId + "";
            }
            return JsonNormal(InvokeService("GetData", new object[] { param }));
        }

        [ActionLog("查询当前单位暂存的记录")]
        [ApiActionPermission("zm_data_record", ActionPermissionOptions.Search)]
        [HttpPost, Route("GetWorkUnitByState")]
        public ActionResult GetWorkUnitByState([FromBody] zmdatarecordQuery param)
        {
            if (UserContext.Current.RoleId == 132 || UserContext.Current.RoleId == 133 || UserContext.Current.RoleId == 126 || UserContext.Current.RoleId == 137)
            {
                param.xzqdm = UserContext.Current.XzqDm;
                param.citydm = UserContext.Current.CityDm;
                param.provcode = UserContext.Current.ProvCode;

            }

            if (UserContext.Current.RoleId == 126 || UserContext.Current.RoleId == 137)
            {
                param.userid = UserContext.Current.UserId + "";
            }
            return JsonNormal(InvokeService("GetWorkUnitByState", new object[] { param }));
        }




        [HttpPost, Route("AdminGetDetaileByID")]
        public ActionResult AdminGetDetaileByID([FromQuery] string id)
        {
            var res = InvokeService("AdminGetDetaileByID", new object[] { id }) as WebResponseContent; ;
            Logger.Info(Core.Enums.LoggerType.Info, id, res.Status ? "Ok" : res.Message);
            return JsonNormal(res);
        }
        private object InvokeService(string methodName, object[] parameters)
        {

            return Service.GetType().GetMethod(methodName).Invoke(Service, parameters);
        }
    }
}
